package cn.xopencode.appletweb.controller;

import cn.xopencode.common.framework.vo.CommonResult;
import cn.xopencode.common.framework.vo.PageResult;
import cn.xopencode.score.api.rpc.ScoreRpc;
import cn.xopencode.score.api.rpc.demand.dto.ScoreAllDTO;
import cn.xopencode.score.api.rpc.demand.dto.ScoreReqDTO;
import cn.xopencode.score.api.rpc.demand.dto.ScoreRespDTO;
import cn.xopencode.securityservice.rpc.suggest.SuggestRpc;
import cn.xopencode.securityservice.rpc.suggest.dto.SuggestRespDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Api(tags = "测试 API")
@RestController
@RequestMapping("/test")
@Validated
public class TestController {

//    @DubboReference(version = "${dubbo.consumer.SuggestRpc.version}")
//    private SuggestRpc suggestRpc;
//    @DubboReference(version = "${dubbo.consumer.ActivityRpc.version}")
//    private ActivityRpc activityRpc;

    @DubboReference(version = "${dubbo.consumer.ScoreRpc.version}")
    private ScoreRpc scoreRpc;

    @DubboReference(version = "${dubbo.consumer.ScoreRpc.version}")
    private SuggestRpc suggestRpc;

/*    @ApiOperation(value = "获取分数列表数据")
    @GetMapping("/findAll")
    public CommonResult<PageResult<ScoreRespDTO>> test() {

        CommonResult<PageResult<ScoreRespDTO>> scoreList = scoreRpc.getScoreList();
        System.out.println(scoreList);
        return scoreList;
    }*/

    @ApiOperation(value = "获取分数列表数据")
    @GetMapping("/findAll/{empId}")
    public CommonResult<List<ScoreAllDTO>> findScoreDetails(@PathVariable(value="empId",required = false)String empId) {
/*        String result = recordTestRpc.test();
        System.out.println(result);*/
//        CommonResult<String> a = scoreRpc.getScoreDetails(new ScoreReqDTO());
        ScoreReqDTO scoreReqDTO = new ScoreReqDTO();
        scoreReqDTO.setId(empId);
        scoreReqDTO.setPageNo(1);
        scoreReqDTO.setPageSize(5);
        scoreReqDTO.setEmpId(empId);
        System.out.println("empId:"+empId);
        CommonResult<List<ScoreAllDTO>> scoreDetails = scoreRpc.getScoreDetails(scoreReqDTO.getEmpId());
        System.out.println("scoreDetails:"+scoreDetails);
        return scoreDetails;
    }

    @ApiOperation(value = "根据修改日期获取分数列表数据")
    @GetMapping("/findScoreFromDate/{date}")
    public CommonResult<ScoreRespDTO> findScoreFromDate(@PathVariable(value="date",required = false)String date) {
/*        String result = recordTestRpc.test();
        System.out.println(result);*/
//        CommonResult<String> a = scoreRpc.getScoreDetails(new ScoreReqDTO());
        ScoreReqDTO scoreReqDTO = new ScoreReqDTO();
        //TODO 如果员工修改记录都在同一月份同一天怎么办
        System.out.println("初始data:"+date);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date parseDate = null;
        try {
            System.out.println("进入");
            parseDate = simpleDateFormat.parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        scoreReqDTO.setUpdateTime(parseDate);
        System.out.println("getUpdateTime():"+scoreReqDTO.getUpdateTime());
        scoreReqDTO.setEmpId("1001");
        scoreReqDTO.setPageNo(1);
        scoreReqDTO.setPageSize(5);
        CommonResult<ScoreRespDTO> dateScoreList = scoreRpc.getScoreFromDate(scoreReqDTO);
        System.out.println("dateScoreList:"+dateScoreList);
        return dateScoreList;
    }
    @ApiOperation(value = "获得创新与合理化建议情况")
    @GetMapping("/getSuggest/{suggestId}")
    public CommonResult<SuggestRespDTO> getSuggest(@PathVariable(value="suggestId",required=false)String suggestId) {
        return suggestRpc.getSuggest(suggestId);
    }
}
